<?php

/**
 * @copyright since 8:27 25/3/2020
 * @author <mc@dancis.info>
 */

const SYMBOL_TIMES = '×';

/** @deprecated */
const SYMBOL_TIMES_EMOJI = '✖';

function main()
{
    /**
     * Once runtime is under Windows, whatever that's a bash, Windows command prompt, or PowerShell.
     *
     * By tested, effective in:
     * - Windows command prompt
     * - Git bash under Windows
     * @todo Might should be improved.
     */
    if (DIRECTORY_SEPARATOR === '\\') {
        system('CHCP 65001'); // Init for UTF-8
    }

    echo 'Multiplication table:', PHP_EOL;

    foreach (range(1, 9) as &$factor2) {
        foreach (range(1, 9) as &$factor1) {
            if ($factor1 <= $factor2) {
                if ($factor1 !== 1) {
                    echo "\t";
                }

                echo
                $factor1,
                str_pad(SYMBOL_TIMES, 4, ' ', STR_PAD_BOTH),
                $factor2,
                str_pad('=', 3, ' ', STR_PAD_BOTH),
                str_pad($factor1 * $factor2, 2, ' ', STR_PAD_LEFT);
            }
        }
        echo PHP_EOL;
    }
}

main();
